﻿//   DiagnosticCategoryCollection.cs
//   Copyright (c) 2012 Eswar Prakash
// 
//    This library is free software; you can redistribute it and/or modify  
//    it  under the terms of the GNU Lesser General Public License version  
//    2.1 as published by the Free Software Foundation.                     
//                                                                          
//    This library is distributed in the hope that it will be useful, but   
//    WITHOUT ANY WARRANTY; without even the implied warranty of            
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     
//    Lesser General Public License for more details.                       
//                                                                          
//    You should have received a copy of the GNU Lesser General Public      
//    License along with this library; if not, write to the Free Software   
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  
//    USA                                                                 
// 

namespace CKSAS.Core.Diagnostics
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections.ObjectModel;
    using Microsoft.SharePoint.Administration;
    using Utilities;

    /// <summary>
    /// 
    /// </summary>
    internal class DiagnosticCategoryCollection : SPDiagnosticsCollection<SPDiagnosticsCategory>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DiagnosticCategoryCollection"/> class.
        /// </summary>
        /// <param name="categories">The categories.</param>
        public DiagnosticCategoryCollection(IEnumerable<SPDiagnosticsCategory> categories)
            : base(categories)
        {
        }

        /// <summary>
        /// Gets or sets the <see cref="Microsoft.SharePoint.Administration.SPDiagnosticsCategory"/> with the specified ERROR.
        /// </summary>
        public SPDiagnosticsCategory this[DiagnosticCategories category]
        {
            get
            {
                // get the category name for looking up the collection
                string categoryName = Enum.GetName(typeof (DiagnosticCategories), category).AsTitle();
                if (!String.IsNullOrEmpty(categoryName))
                {
                    return this.FirstOrDefault(x => x.Name.Equals(categoryName));
                }

                return null;
            }
        }
    }
}